<template>
    <h2>添加页面</h2>
    <table>
        <tr>
            <td>项目名称:</td>
            <td>
                <input type="text" v-model="F_Name" id="F_Name">
            </td>
        </tr>
        <tr>
            <td>年收益:</td>
            <td>
                <input type="text" v-model="F_YearMon" id="F_YearMon">
            </td>
        </tr>
        <tr>
            <td>月收益:</td>
            <td>
                <input type="text" v-model="F_Month" id="F_Month">
            </td>
        </tr>
        <tr>
            <td>最低金额:</td>
            <td>
                <input type="text" v-model="F_MinMon" id="F_MinMon">
            </td>
        </tr>
        <tr>
            <td>理财人数:</td>
            <td>
                <input type="text" v-model="F_Num" id="F_Num">
            </td>
        </tr>
        <tr>
            <td>风险等级:</td>
            <td>
                <input type="radio" value="0" v-model="F_Level" name="F_Level" checked>低风险
                <input type="radio" value="1" v-model="F_Level" name="F_Level">中风险
                <input type="radio" value="2" v-model="F_Level" name="F_Level">高风险
            </td>
        </tr>
        <tr>
            <td>利息:</td>
            <td>
                <select v-model="T_Id">
                    <option value="0">--请选择--</option>
                    <option v-for="item in opt" :key="item.T_Id" :value="item.T_Id">{{ item.Interest }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="添加" @click="add">
            </td>
        </tr>
    </table>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { onMounted } from 'vue';
import axios from 'axios';


const opt = ref([]);

const F_Name = ref('');
const F_YearMon = ref('');
const F_Month = ref('');
const F_MinMon = ref('');
const F_Num = ref('');
//默认选择低风险
const F_Level = ref(0);
//默认请选择
const T_Id = ref(0);

onMounted(() => {
    axios.get('http://localhost:9011/api/Demo/Bind')
        .then(res => {
            opt.value = res.data;
        })
        .then(error => {
            console.log(error);
        })
})

const add = () => {
    if (!F_Name.value) {
        alert("项目名称不能为空");
        return;
    }
    if (!F_YearMon.value) {
        alert("年收益不能为空");
        return;
    }
    if (!F_Month.value) {
        alert("月收益不能为空");
        return;
    }
    if (!F_MinMon.value) {
        alert("最低金额不能为空");
        return;
    }
    axios.post('http://localhost:9011/api/Demo/Add', {
        F_Name: F_Name.value,
        F_YearMon: F_YearMon.value,
        F_Month: F_Month.value,
        F_MinMon: F_MinMon.value,
        F_Num: F_Num.value,

        F_Level: F_Level.value,

        T_Id: T_Id.value,
    })
        .then(res => {
            if (res.data > 0) {
                alert("添加成功");
                location.href = '/FinanShow'
                return;
            }
            else {
                alert("添加失败");
                return;
            }
        })
        .then(error => {
            console.log(error);
        })
}
</script>